<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>ES5 新增特性汇总 | 云飞扬 - 个人博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687- Trailing commas are ok多余的逗号不报错，比如">
<meta property="og:type" content="article">
<meta property="og:title" content="ES5 新增特性汇总">
<meta property="og:url" content="http://blog.yxxit.com/2017/01/19/es5/index.html">
<meta property="og:site_name" content="云飞扬 - 个人博客">
<meta property="og:description" content="123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687- Trailing commas are ok多余的逗号不报错，比如">
<meta property="og:updated_time" content="2017-02-10T04:48:12.504Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="ES5 新增特性汇总">
<meta name="twitter:description" content="123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687- Trailing commas are ok多余的逗号不报错，比如">
  
    <link rel="alternate" href="/atom.xml" title="云飞扬 - 个人博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/view/favicon.ico">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/view/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/view/" id="logo">云飞扬 - 个人博客</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/view/">Home</a>
        
          <a class="main-nav-link" href="/view/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://blog.yxxit.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-es5" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/view/2017/01/19/es5/" class="article-date">
  <time datetime="2017-01-19T12:32:09.472Z" itemprop="datePublished">2017-01-19</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      ES5 新增特性汇总
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">- Trailing commas are ok</div><div class="line">多余的逗号不报错，比如 &#123;a:1,b:2,&#125;</div><div class="line"></div><div class="line">- No reserved words for property names</div><div class="line">属性名可以使用关键字和保留字了，比如 &#123; if:1, else:2 &#125;</div><div class="line"></div><div class="line">- NaN, Infinity, undefined : are all constants</div><div class="line">NaN、Infinity、undefined 都是常量了，不可更改。</div><div class="line"></div><div class="line">- parseInt() defaults to radix 10</div><div class="line">parseInt 第二个参数默认为 10（真好）</div><div class="line"></div><div class="line">- /regexp/ produces new reg ex object every time</div><div class="line">正则字面量每次都会产生一个新的对象</div><div class="line"></div><div class="line">- JSON.parse(), JSON.stringify()</div><div class="line">添加 JSON 序列化和反序列化</div><div class="line"></div><div class="line">- Function.prototype.bind</div><div class="line">函数新增 bind 方法（贺老说 bind 写在后面有点不好用）</div><div class="line"></div><div class="line">- String.prototype.trim</div><div class="line">字符串终于自带头尾去空格方法了，如 &apos; abc &apos;.trim() === &apos;abc&apos;</div><div class="line"></div><div class="line">- Array.prototype.every, filter, forEach, indexOf, lastIndexOf, map, reduce, reduceRight, some</div><div class="line">数组添加了一系列方法，终于能脱离 Underscore.js 了</div><div class="line"></div><div class="line">- Date.now()</div><div class="line">Date.now 现在才加进来的？可怕。</div><div class="line"></div><div class="line">- Date.prototype.toISOString</div><div class="line">日期新增 toISOString 方法</div><div class="line"></div><div class="line">- new Date(string) and Date.parse(string) will try ISO format 1st</div><div class="line">新增对 ISO 日期格式的支持</div><div class="line"></div><div class="line">- Array.isArray()</div><div class="line">判断一个对象是不是数组……以前苦了大家了</div><div class="line"></div><div class="line">- Object.keys(), Object.create(), Object.defineProperty, Object.defineProperties,</div><div class="line">Object.getOwnPropertyDescriptor(), Object.getOwnPropertyNames(obj), Object.getPrototypeOf(obj)</div><div class="line">- Object.seal(), Object.freeze(), Object.preventExtensions(), Object.isSealed(), Object.isFrozen(),</div><div class="line">Object.isExtensible()</div><div class="line">对象新增一系列方法，使得在 JS 中模拟 Java 变得更丝滑。我最喜欢的还是 Object.create()</div><div class="line"></div><div class="line">- Property attributes: writeable, value, enumerable, configurable, get, set</div><div class="line">对象的属性可以添加各种配置了</div><div class="line"></div><div class="line">- &apos;use strict&apos;;</div><div class="line">- Strict Mode:</div><div class="line">  No more implied global variables within functions.</div><div class="line">  this is not bound to the global object by function form.</div><div class="line">  apply and call do not default to the global object.</div><div class="line">  No with statement.</div><div class="line">  Setting a writeable: false property will throw.</div><div class="line">  Deleting a configurable: false property will throw.</div><div class="line">  Restrictions on eval.</div><div class="line">  eval and arguments are reserved.</div><div class="line">  arguments not linked to parameters.</div><div class="line">  No more arguments.caller or arguments.callee.</div><div class="line">  No more octal literals.</div><div class="line">  Duplicate names in an object literal or function parameters are a syntax error</div><div class="line"></div><div class="line">严格模式</div><div class="line">函数里没有隐式的全局变量了，你要创建全局变量必须是显式的。比如想用 a = 1 创建全局变量是不行的。</div><div class="line">this 不会默认指向全局对象（比如 window 或者 global）了。</div><div class="line">call 和 apply 也不会默认使用全局对象了。</div><div class="line">不准用 with</div><div class="line">如果一个属性的 writeable 是 false，那么你给这个属性赋值就会报错。</div><div class="line">如果一个属性的 configurable 是 false，那么你 delete 这个属性就会报错。</div><div class="line">对 eval 和 arguments 做出了限制。以下代码每行都会报错：</div><div class="line"></div><div class="line">  eval = 17;</div><div class="line">  arguments++;</div><div class="line">  ++eval;</div><div class="line">  var obj = &#123; set p(arguments) &#123; &#125; &#125;;</div><div class="line">  var eval;</div><div class="line">  try &#123; &#125; catch (arguments) &#123; &#125;</div><div class="line">  function x(eval) &#123; &#125;</div><div class="line">  function arguments() &#123; &#125;</div><div class="line">  var y = function eval() &#123; &#125;;</div><div class="line">  var f = new Function(&quot;arguments&quot;, &quot;&apos;use strict&apos;; return 17;&quot;);</div><div class="line">arguments 只保存原始参数。对形参的赋值不会对 arguments 有影响。</div><div class="line">不准用 arguments.caller 和 arguments.callee</div><div class="line">不支持八进制字面量，比如 var a = 015 会报错。</div><div class="line">对象字面量或者函数形参中，如果有重复的名字，就会报错。</div></pre></td></tr></table></figure>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><ul>
<li><a href="https://zhuanlan.zhihu.com/p/24336831" target="_blank" rel="external">转载</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://blog.yxxit.com/view/2017/01/19/es5/" data-id="ciy4cxh330000ksddol602gtj" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/view/2017/01/22/Spring.boot 项目创建之傻瓜教程/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Spring.boot 项目创建之傻瓜教程
        
      </div>
    </a>
  
  
    <a href="/view/2017/01/19/nodejs开发规范/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">node.js 开发规范</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/view/tags/node-js-规范/">node.js, 规范</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/view/tags/node-js-规范/" style="font-size: 10px;">node.js, 规范</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/view/archives/2017/03/">March 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/view/archives/2017/02/">February 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/view/archives/2017/01/">January 2017</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/view/2017/03/21/npm/">npm 常用命令</a>
          </li>
        
          <li>
            <a href="/view/2017/03/21/git/">Git 常用命令</a>
          </li>
        
          <li>
            <a href="/view/2017/03/05/windows nginx natapp/">windows nginx natapp</a>
          </li>
        
          <li>
            <a href="/view/2017/02/17/node.js 模块之 pm2/">node.js 模块之 pm2</a>
          </li>
        
          <li>
            <a href="/view/2017/02/16/node.js 6.9.4 升级/">node.js 6.9.4 升级</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 coolshaw<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/view/" class="mobile-nav-link">Home</a>
  
    <a href="/view/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>


  <link rel="stylesheet" href="/view/fancybox/jquery.fancybox.css">
  <script src="/view/fancybox/jquery.fancybox.pack.js"></script>


<script src="/view/js/script.js"></script>

  </div>
</body>
</html>